import re
from utils.log import logger
class GroupByRecognition():
    def __init__(self):
        pass
    def group_by(self,queru,sel,agg , measure):
        """
        group_by字段识别方法
        1. 一般时间维度都包含在group_by
        2. 一般有聚合函数group_by字段才不为空
        :param question:
        :param sel:
        :param agg:
        :param measure:
        :return:
        """
        try:
            group_by = []
            # 简单的把没有聚合操作且为维度类型的列头id包含在group_by中
            for index, col_head in enumerate(sel):
                id = col_head['id']
                if agg[index] == "" and id not in measure:
                    group_by.append(id)

            return group_by
        except Exception as err:
            logger.error("some errors happened in group_by[{}]: {}".format(type(err),str(err)))
            raise
